package com.designpattern.simplefactory.ordinary;

import java.util.Scanner;

/**
 * @author Liusr
 * @date 2023/2/27
 * @package com.designpattern.simplefactory.ordinary
 * @Description: 计算器客户端
 */
public class CalculatorClient {
	/**
	 *简单工厂模式
	 * 工厂通过运算符创建具体的运算操作类，而操作类继承了操作抽象类。
	 * 运算分离，代码复用性提高，修改或增加一个运算方法不会影响到其他代码
	 */
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入numberA:");
		double numberA = sc.nextDouble();
		sc.nextLine();
		System.out.println("请输入运算符号(+、-、*、/):");
		String operatorChar = sc.nextLine();
		System.out.println("请输入numberB:");
		double numberB = sc.nextDouble();
		Operator operator = OperatorFactory.getResult(operatorChar);
		operator.setNumberA(numberA);
		operator.setNumberB(numberB);
		System.out.println(operator.getResult());
	}
}
